package org.smart4j.framework.helper;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smart4j.framework.ConfigConstant;

import static org.smart4j.framework.ConfigConstant.CONFIG_FILE;

/**
 * Created by Wenxin on 2017/2/22.
 */
final public class ConfigHelper {

    final static Logger log = LoggerFactory.getLogger(ConfigHelper.class);

    private static class ConfigHelperConstant{
        static Configuration CONFIG;
        static {
            try {
                CONFIG = new PropertiesConfiguration(CONFIG_FILE);
            } catch (ConfigurationException e) {
                if (log.isTraceEnabled()){
                    log.trace("Loading config file has errors : ",e);
                }
            }
        }
    }

    /**
     * 获取jdbc驱动
     * @return
     */
    public static String getJdbcDriver(){
        return ConfigHelperConstant.CONFIG.getString(ConfigConstant.JDBC_DRIVER);
    }

    /**
     * 获取jdbc url
     * @return
     */
    public static String getJdbcUrl(){
        return ConfigHelperConstant.CONFIG.getString(ConfigConstant.JDBC_URL);
    }

    /**
     * 获取jdbc用户名
     * @return
     */
    public static String getJdbcUsername(){
        return ConfigHelperConstant.CONFIG.getString(ConfigConstant.JDBC_USERNAME);
    }

    /**
     * 获取jdbc密码
     * @return
     */
    public static String getJdbcPassword(){
        return ConfigHelperConstant.CONFIG.getString(ConfigConstant.JDBC_PASSWORD);
    }

    /**
     * 获取jdbc驱动
     * @return
     */
    public static String getAppBasePackage(){
        return ConfigHelperConstant.CONFIG.getString(ConfigConstant.APP_BASE_PACKAGE);
    }

    /**
     * 获取jdbc驱动
     * @return
     */
    public static String getAppJspPath(){
        return ConfigHelperConstant.CONFIG.getString(ConfigConstant.APP_JSP_PATH);
    }

    /**
     * 获取jdbc驱动
     * @return
     */
    public static String getAppAssetPath(){
        return ConfigHelperConstant.CONFIG.getString(ConfigConstant.APP_ASSET_PATH);
    }

}
